package com.joesem.sale.client.logic.workOrder.option.viewModel

import android.app.Application
import android.util.Log
import com.joesem.sale.client.base.BaseViewModel
import com.joesem.sale.client.base.request
import com.joesem.sale.client.base.toast
import com.joesem.sale.client.network.data.AreaMode


class AreaViewModel(application: Application) : BaseViewModel(application) {

    fun getArea(parentId: Int? = null) {
        request(isLoading = true, request = {
            getArea(parentId)
        }, response = { it ->
            actionIntent(AreaIntent(it.data?.filterNotNull()?.filterNot { it.name.isNullOrEmpty() }
                ?: arrayListOf()))
        }, responseFailed = {
            toast(it.message)
            actionIntent(AreaIntent(arrayListOf()))
        })
    }

    class AreaIntent(val data: List<AreaMode>)
}